<template>
  <div>
    <FormTable :formData="formData"
               :columnData="columnData"
               :editData="editData"
               :url="$api.orders_getcountlist"
               :is_default_edit="true"
               :is_show_export="true"
               :export_url="$api.orders_getcountexport"
               :pageConfig="pageConfig"></FormTable>
  </div>
</template>

<script>
export default {
  data () {
    return {
      formData: [
        {
          name: "rights_id",
          label: "权益名称",
          value: '',
          type: "select",
          config: {
            filterable: true
          },
          groups: [
          ],
        },
        {
          name: "card_id",
          label: "卡卷名称",
          value: '',
          type: "select",
          config: {
            filterable: true
          },
          groups: [
          ],
        },
        {
          name: "order_day",
          label: "订单时间",
          value: '',
          type: "date_time_range",
          width:'500px',
          config: {
            format: 'yyyy-MM-dd HH:mm:ss',
            'value-format': 'yyyy-MM-dd HH:mm:ss',
            align: 'left'
          },
        },
        {
          name: "type",
          label: "订单类型",
          value: '',
          type: "select",
          config: {
            filterable: true,
            multiple: true
          },
          groups: [
            {
              label: '所有',
              value: ''
            },
            {
              value: 1,
              label: '权益'
            },
            {
              value: 2,
              label: '卡券'
            },
            {
              value: 3,
              label: '渠道'
            },
            {
              value: 4,
              label: '分类'
            },
          ],
        },
        {
          name: "time_type",
          label: "时间类型",
          value: '',
          type: "select",
          config: {
            filterable: true
          },
          groups: [
            {
              label: '所有',
              value: ''
            },
            {
              value: 1,
              label: '日期'
            },
            {
              value: 2,
              label: '月份'
            },
            {
              value: 3,
              label: '年份'
            },
          ],
        },
      ],
      columnData: [
        {
          prop: "rights_name",
          label: "权益名称"
        },
        {
          prop: "card_name",
          label: "卡券名称"
        },
        {
          prop: "qd",
          label: "渠道"
        },
        {
          prop: "payMoney",
          label: "支付金额"
        },

        {
          prop: "orders_count",
          label: "订单数"
        },
        {
          prop: "pay_count",
          label: "支付成功订单数"
        },
        {
          prop: "pay_count_rate",
          label: "支付成功率"
        },
        {
          prop: "no_pay_count",
          label: "未支付订单数"
        },
        {
          prop: "issued_count",
          label: "权益下发成功数"
        },
        {
          prop: "issued_count_rate",
          label: "权益下发率"
        },
        {
          prop: "total_pay_amount",
          label: "支付总金额"
        },
        {
          prop: "total_pay_amount",
          label: "支付总金额"
        },
        {
          prop: "payMoney",
          label: "支付金额"
        },
        {
          prop: "create_day",
          label: "创建时间"
        },
      ],
      editData: [],
      pageConfig: {
        page: 1,
        pagesize: 10,
      }
    };
  },
  created () {
    this.getTopType();
  },
  methods: {
    getTopType () {
      // 获取权益列表
      let req1 = this.$req.get(this.$api.rights_getnopagelist)
      // 获取卡卷列表
      let req2 = this.$req.get(this.$api.card_getnopagelist)
      Promise.all([req1, req2]).then(values => {
        this.dataHandler(values[0].data, 0, '', 'name', 'rights_id');
        this.dataHandler(values[1].data, 1, '', 'name', 'card_id');
      })
    },
    dataHandler (data, idx1, idx2, labelKey, valueKey) {
      for (var i in data) {
        if (typeof idx1 == 'number') {
          this.formData[idx1].groups.push({
            label: labelKey ? data[i][labelKey] : data[i],
            value: valueKey ? data[i][valueKey] : data[i]
          })
        }
      }
      console.log(this.editData)
    },
    handleSizeChange (e) {
      console.log(e);
    },
    handleCurrentChange (e) {
      console.log(e);
    },
    submit (e) {
      console.log(e);
    },
    reset (e) {
      console.log(e);
    }
  }
}
</script>

<style lang="scss" scoped>
</style>